package com.wangsd.system.service;

import com.gitee.fastmybatis.core.query.Query;
import com.gitee.fastmybatis.core.query.Sort;
import com.wangsd.system.entity.Merchant;
import com.wangsd.system.mapper.MerchantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户Service业务层处理
 *
 * @author wsd
 * @date 2021-03-16
 */
@Service
public class MerchantService {
    @Autowired
    private MerchantMapper mapper;

    /**
     * 查询商户
     *
     * @param id 商户ID
     * @return 商户
     */
    public Merchant selectMerchantById(Long id) {
        return mapper.getById(id);
    }

    /**
     * 查询商户列表
     *
     * @param merchant 商户
     * @return 商户
     */
    public List<Merchant> selectMerchantList(Merchant merchant) {
        Query query = new Query();
        if (merchant.getMerchantName() != null) {
            query.like("merchant_name",merchant.getMerchantName());
        }
        query.orderby("id", Sort.DESC);
        List<Merchant> list = mapper.list(query);
        return list;
    }

    /**
     * 新增商户
     *
     * @param merchant 商户
     * @return 结果
     */
    public int insertMerchant(Merchant merchant) {
        return mapper.saveIgnoreNull(merchant);
    }

    /**
     * 修改商户
     *
     * @param merchant 商户
     * @return 结果
     */
    public int updateMerchant(Merchant merchant) {
        return mapper.updateIgnoreNull(merchant);
    }

    /**
     * 删除商户信息
     *
     * @param id 商户ID
     * @return 结果
     */
    public int deleteMerchantById(Long id) {
        return mapper.deleteById(id);
    }
}
